<!-- 柱状图 -->
<style lang="stylus" scoped>
.column
  height 100%
  background-size 100% 100%
  color white
  .main
    width 100%
    height calc(100% - 100px)
</style>

<template>
<div class="column">
  <p style='font-family:微软雅黑;font-size:16px;color:#0B903C;font-weight:bold;line-height:50px;'>全市重点人员概况</p>
  <div class="main"></div> 
</div>

</template>
<script>
import echarts from 'echarts'
import header from 'components/header/header'
import filter from 'components/filter/filter'
import axios from 'axios'
export default {
  data() {
    return {
      legendArr: [],
      color: this.$store.state.color,
      styleArr: [],
      myChart: {},
      name: ''
    }
  },
  methods: {
    _init() {
      var areaname = localStorage.getItem('areaname');
      if (!areaname) {
        areaname = '平顶山市';
      }
      this.myChart = echarts.init(document.querySelector('.column .main'))
      var glo = this.GLOBAL.BASE_URL;
      this.myChart.on("click", function(params) {
        $(".table").show();
        if (params.name === "刑满释放人员") {
          $(".table iframe").attr("src", glo + "/a/anzhi/anzhiMain/vuelist").show();
        } else if (params.name === "吸毒人员") {
          $(".table iframe").attr("src", glo + "/a/jindu/jinduMain/vuelist").show();
        } else if (params.name === "社区矫正人员") {
          $(".table iframe").attr("src", glo + "/a/shejiao/shejiaoMain/vuelist").show();
        } else if (params.name === "特定利益群体") {
          $(".table iframe").attr("src", glo + "/a/weiwen/weiwenMain/vuelist").show();
        } else if (params.name === "严重精神障碍患者") {
          $(".table iframe").attr("src", glo + "/a/weiji/weijiMain/vuelist").show();
        } else if (params.name === "赴京省访重点人员") {
          $(".table iframe").attr("src", glo + "/a/xinfang/axinfangMain/vuelist").show();
        } else if (params.name === "在逃人员") {
          $(".table iframe").attr("src", glo + "/a/zaitao/zaitaoMain/vuelist").show();
        } else if (params.name === "邪教人员") {
          $(".table iframe").attr("src", glo + "/a/xiejiao/xiejiaoMain/vuelist").show();
        }
      })
      this.legendArr = this.myChart.getOption().series
      this.legendArr.forEach((data) => {
        data.selected = true;
      })
      this.$root.charts.push(this.myChart)
      window.addEventListener('resize', function() {
        this.myChart.resize()
      }.bind(this))
    }
  },
  components: {
    'v-header': header,
    'v-filter': filter
  },
  mounted() {
    // 基于准备好的dom，初始化echarts实例
    this.myChart = echarts.init(document.querySelector('.column .main'))
    axios.get(this.GLOBAL.BASE_URL + '/a/sys/area/mapData?name=平顶山市').then((res) => {
    // axios.get('static/data/Data.json').then((res) => {
      if (res) {
        var arr;
        $(res.data).each(function() {
          if (this.name === "平顶山市") {
            arr = this.value.split(",").slice(0, 8);
          }
        })
        this.myChart.setOption({
          title: {
            show: true
          },
          tooltip: {
            trigger: 'axis'
          },
          legend: {
            show: false
          },
          toolbox: {
            show: false
          },
          color: this.color,
          calculable: true,
          xAxis: [{
            name: '类型',
            type: 'category',
            axisLine: {
              show: true,
              lineStyle: {
                color: '#00AA5E'
              }
            },
            axisTick: {
              show: false
            },
            nameTextStyle: {
              color: 'rgba(0, 115, 86, 1)',
              fontWeight: 'bold'
            },
            axisLabel: {
              rotate: 50,
              textStyle: {
                color: 'rgba(11, 144, 60, 1)',
                fontWeight: 'bold',
                fontSize: '10'
              }
            },
            data: ['刑满释放人员', '吸毒人员', '社区矫正人员', '特定利益群体', '严重精神障碍患者', '赴京省访重点人员', '在逃人员', '邪教人员']
          }],
          yAxis: [{
            axisLine: {
              show: true,
              lineStyle: {
                color: '#00AA5E'
              }
            },
            nameLocation: 'end',
            nameGap: 20,
            nameRotate: 0,
            axisTick: {
              show: false
            },
            splitLine: {
              show: false
            },
            axisLabel: {
              textStyle: {
                color: 'rgba(11, 144, 60, 1)',
                fontWeight: 'bold',
                fontSize: 14
              }
            },
            name: '人数',
            type: 'value',
            nameTextStyle: {
              color: 'rgba(11, 144, 60, 1)',
              fontWeight: 'bold'
            }
          }],
          grid: {
            bottom: 75,
            left: 45,
            right: 45
          },
          series: [{
            name: '重点人员',
            stack: 'stack2',
            type: 'bar',
            data: arr,
            barWidth: 16,
            barGap: 0,
            color: ['#00AA5E'],
            itemStyle: {
              normal: {
                barBorderRadius: [5, 5, 0, 0],
                label: {
                  formatter: function (params) {
                    if (params.value > 0) {
                      return params.value + "人";
                    } else {
                      return "";
                    }
                  },
                  show: true,
                  color: '#00AA5E',
                  position: 'top',
                  fontWeight: 'bold'
                }
              }
            }
          }]
        });
        this._init()
      }
    });
  }
}

</script>